home *** CD-ROM | disk | FTP | other *** search
/ Star Trek Starfleet Academy Mini Omnipedia / MINI_OMNI.ISO / pc / omni_v2.dxr / 00415_windows voice rec.ls < prev    next >
Encoding:
Text File  |  1996-04-15  |  11.0 KB  |  416 lines

  1. global gWinVoiceXobj, gVoiceCmd, gVoiceConfidence, gVoiceHandler, gVoiceDisabled, gWinVoiceLastCmd, gWINListenStatus, gWinVoiceEnabled, gTrekCursor, gSpeechCapable, gWINvoiUserPermit, gVoicemode, gMaxLinks, gWinVoiceStartedWaiting, gSpeechWasChosenF, gModeState, gVidIsPlaying, gWinVoiceSuspended, gCurrentlyPlayingMovie
  2.  
  3. on hGetTextOfFile fileName
  4.   set fileText to EMPTY
  5.   if hFileIsHere(fileName) then
  6.     openXLib("fileio.dll")
  7.     set tempobj to FileIO(mnew, "read", fileName)
  8.     if not objectp(tempobj) then
  9.       alert("Your STARTREK.INI is missing or damaged.")
  10.       return 
  11.     end if
  12.     set fileText to tempobj(mReadFile)
  13.     tempobj(mdispose)
  14.     closeXLib("fileio.dll")
  15.   end if
  16.   return fileText
  17. end
  18.  
  19. on hINIFileCheck INIFileName, sectionName, varName
  20.   set txt to hGetTextOfFile(INIFileName)
  21.   if char 1 of sectionName <> "[" then
  22.     put "[" before sectionName
  23.   end if
  24.   if char length(sectionName) of sectionName <> "]" then
  25.     put "]" after sectionName
  26.   end if
  27.   set n to the number of lines in txt
  28.   set LINEBREAK to numToChar(10)
  29.   set oldDelim to the itemDelimiter
  30.   set retVal to EMPTY
  31.   set the itemDelimiter to "="
  32.   repeat with i = 1 to n
  33.     set txtLine to line i of txt
  34.     if char 1 of txtLine = LINEBREAK then
  35.       delete char 1 of txtLine
  36.     end if
  37.     if txtLine = sectionName then
  38.       repeat with j = i + 1 to n
  39.         set txtLine to line j of txt
  40.         if char 1 of txtLine = LINEBREAK then
  41.           delete char 1 of txtLine
  42.         end if
  43.         if item 1 of txtLine = varName then
  44.           set retVal to item 2 to 1000 of txtLine
  45.           exit repeat
  46.         end if
  47.       end repeat
  48.     end if
  49.     if retVal <> 0 then
  50.       exit repeat
  51.     end if
  52.   end repeat
  53.   set the itemDelimiter to oldDelim
  54.   return retVal
  55. end
  56.  
  57. on hBotherCheckingForWinVersions
  58.   set retVal to 0
  59.   if hINIFileCheck(the pathName & "OMNI_SP.INI", "winVersionCheck", "stopOnWin95") = 1 then
  60.     set retVal to 1
  61.   end if
  62.   return retVal
  63. end
  64.  
  65. on hWinVoiceAvailable
  66.   global gProjectorPath
  67.   set fileList to "dragdev.dll,dragon.dll,environ.dll,fileio.dll,wintalkd.dll"
  68.   set oldDelim to the itemDelimiter
  69.   set the itemDelimiter to ","
  70.   set n to the number of items in fileList
  71.   set avail to 1
  72.   repeat with i = 1 to n
  73.     set thefile to item i of fileList
  74.     if not hFileIsHere(gProjectorPath & thefile) then
  75.       put thefile && "is missing!!!!!!!!!!!!!!!!!!!"
  76.       set avail to 0
  77.       next repeat
  78.     end if
  79.     put thefile && "is here."
  80.   end repeat
  81.   set the itemDelimiter to oldDelim
  82.   return avail
  83. end
  84.  
  85. on hWINenvirVerify
  86.   if not hFileIsHere(the moviePath & "ENVIRON.DLL") then
  87.     cursor([gTrekCursor, gTrekCursor + 1])
  88.     set gWinVoiceEnabled to 0
  89.     return 0
  90.   else
  91.     openXLib(the moviePath & "ENVIRON.DLL")
  92.     set Widget to Environment(mnew)
  93.     set winver to Widget(mWinVersion)
  94.     set dosver to Widget(mDosVersion)
  95.     set Lv to float(winver)
  96.     if Lv < 3.20000000000000018 then
  97.       set Lok to 1
  98.     else
  99.       set Lok to 0
  100.     end if
  101.     Widget(mdispose)
  102.     set Widget to 0
  103.     closeXLib(the moviePath & "ENVIRON.DLL")
  104.     return Lok
  105.   end if
  106. end
  107.  
  108. on hWinVoiceGetUsername
  109.   set proposedUsername to hINIFileCheck("OMNI_SP.INI", "filenames", "dragonUserFile")
  110.   set newUsername to "omni.usr"
  111.   if proposedUsername <> EMPTY then
  112.     if hFileIsHere(the moviePath & proposedUsername) then
  113.       set newUsername to proposedUsername
  114.     end if
  115.   end if
  116.   return newUsername
  117. end
  118.  
  119. on hWinVoiceGetVocname
  120.   set proposedVocname to hINIFileCheck("OMNI_SP.INI", "filenames", "dragonVocFile")
  121.   set newVocname to "omni.voc"
  122.   if proposedVocname <> EMPTY then
  123.     if hFileIsHere(the moviePath & proposedVocname) then
  124.       set newVocname to proposedVocname
  125.     end if
  126.   end if
  127.   return newVocname
  128. end
  129.  
  130. on hWinVoiceDebugCheck
  131.   set shouldDebug to 0
  132.   set shouldDebug to hINIFileCheck("OMNI_SP.INI", "misc", "debugging")
  133.   if shouldDebug = "1" then
  134.     gWinVoiceXobj(mStartDebug)
  135.   end if
  136. end
  137.  
  138. on hWinVoiceOpen
  139.   global gComputerTypeK, gProjectorPath
  140.   cursor(4)
  141.   set gWinVoiceEnabled to 0
  142.   set gWINListenStatus to 0
  143.   set gVoiceCmd to EMPTY
  144.   set gVoiceConfidence to EMPTY
  145.   set gWinVoiceLastCmd to EMPTY
  146.   set gSpeechCapable to 0
  147.   set gWinVoiceStartedWaiting to 0
  148.   set gMaxLinks to 20
  149.   set gVoicemode to EMPTY
  150.   if gComputerTypeK <> #WIN then
  151.     return 
  152.   end if
  153.   if gCurrentlyPlayingMovie contains "\" then
  154.     tell window gCurrentlyPlayingMovie
  155.       do("closeWindow")
  156.     end tell
  157.   end if
  158.   if hBotherCheckingForWinVersions() then
  159.     if not hWINenvirVerify() then
  160.       alert("Sorry, the voice recognition software is not compatible with this version of Microsoft Windows. Program will proceed without attempting speech recognition.")
  161.       cursor([gTrekCursor, gTrekCursor + 1])
  162.       set gWinVoiceEnabled to 0
  163.       return 0
  164.     end if
  165.   end if
  166.   puppetSound(0)
  167.   set gWinVoiceEnabled to 1
  168.   set gSpeechCapable to 1
  169.   put "gProjectorPath=" & gProjectorPath
  170.   set Lfilepath to the moviePath & "wintalkd.dll"
  171.   if not hFileIsHere(Lfilepath) then
  172.     cursor([gTrekCursor, gTrekCursor + 1])
  173.     set gWinVoiceEnabled to 0
  174.   end if
  175.   openXLib(Lfilepath)
  176.   put ">hWinWoiceOpen trying to initialize the Xobj at" && Lfilepath
  177.   set gWinVoiceXobj to Widget(mnew)
  178.   if objectp(gWinVoiceXobj) = 0 then
  179.     put ">hWinVoiceOpen COULD NOT OPEN " & Lfilepath
  180.     set gWinVoiceEnabled to 0
  181.     cursor([gTrekCursor, gTrekCursor + 1])
  182.     return 
  183.   end if
  184.   hWinVoiceDebugCheck()
  185.   set username to hWinVoiceGetUsername()
  186.   set vocname to hWinVoiceGetVocname()
  187.   set success to gWinVoiceXobj(mOpenDriver, vocname, username)
  188.   if success = 0 then
  189.     beep()
  190.     set gWinVoiceEnabled to 0
  191.   else
  192.     set gWinVoiceSuspended to 0
  193.     set gWinVoiceEnabled to 1
  194.     set gSpeechCapable to 1
  195.   end if
  196.   set gWINListenStatus to 1
  197.   set gWINListenStatus to 0
  198.   set gCurrentlyPlayingMovie to EMPTY
  199.   hWinVoiceMicOn(0)
  200.   if hWinVoiceMicState() then
  201.     set gWinVoiceStartedWaiting to the ticks
  202.     hReportStatus("Please wait 5 seconds before speaking...")
  203.   end if
  204.   cursor([gTrekCursor, gTrekCursor + 1])
  205. end
  206.  
  207. on hWinVoiceInitInterface
  208.   set gCurrentlyPlayingMovie to EMPTY
  209.   if hWinVoiceAvailable() then
  210.     hShowSpeechStatus(#INACTIVE)
  211.     set gSpeechCapable to 1
  212.   end if
  213. end
  214.  
  215. on hWINvoistats
  216.   put "objectP(gWinVoiceXobj):" & objectp(gWinVoiceXobj)
  217.   put "gSpeechCapable:" & gSpeechCapable
  218.   put "gWinVoiceEnabled:" & gWinVoiceEnabled
  219.   put "gWINListenStatus:" & gWINListenStatus
  220. end
  221.  
  222. on hWinVoiceClose
  223.   if objectp(gWinVoiceXobj) then
  224.     put ">hWinVoiceClose called..."
  225.     if gVoiceDisabled <> "1" then
  226.       put gWinVoiceXobj(mCloseDriver)
  227.       put gWinVoiceXobj(mdispose)
  228.       set gWinVoiceXobj to 0
  229.       closeXLib(the moviePath & "wintalkd.dll")
  230.     end if
  231.   end if
  232.   set gWinVoiceEnabled to 0
  233. end
  234.  
  235. on hWinVoiceMicOn pWithAnnc
  236.   global gCurrentlyPlayingMovie
  237.   updateStage()
  238.   if gCurrentlyPlayingMovie <> EMPTY then
  239.   else
  240.     if objectp(gWinVoiceXobj) then
  241.       if (gModeState = #TOPICS) or gVidIsPlaying then
  242.         return 
  243.       end if
  244.       if gSpeechWasChosenF = 0 then
  245.         return 
  246.       end if
  247.       put "gWinVoiceEnabled=" & gWinVoiceEnabled
  248.       if gWinVoiceEnabled = 1 then
  249.         if gWINListenStatus = 0 then
  250.           puppetSound(0)
  251.           updateStage()
  252.           repeat while soundBusy(1)
  253.             nothing()
  254.           end repeat
  255.           repeat while soundBusy(2)
  256.             nothing()
  257.           end repeat
  258.           gWinVoiceXobj(mSetMicState, 1)
  259.           put "after setmicstate, mic = " & gWinVoiceXobj(mGetMicState)
  260.           if pWithAnnc = 1 then
  261.             put "ANNOUNCING FROM HWINVOICEON"
  262.             hAnnounce("Voice Rec Activated")
  263.           end if
  264.           set gWINListenStatus to 1
  265.           hShowSpeechStatus(#READY)
  266.           hReportStatus("Speech microphone ready...")
  267.         end if
  268.       end if
  269.     end if
  270.   end if
  271. end
  272.  
  273. on hWinVoiceMicOff
  274.   if objectp(gWinVoiceXobj) then
  275.     if gWinVoiceEnabled = 1 then
  276.       if gWINListenStatus = 1 then
  277.         gWinVoiceXobj(mSetMicState, 0)
  278.         set gWinVoiceSuspended to 0
  279.         set gWINListenStatus to 0
  280.         hShowSpeechStatus(#STANDBY)
  281.         hReportStatus("Speech microphone turned off...")
  282.       end if
  283.     end if
  284.   end if
  285. end
  286.  
  287. on hWinVoiceSuspend
  288.   if objectp(gWinVoiceXobj) then
  289.     if gWinVoiceEnabled = 1 then
  290.       if gWINListenStatus = 1 then
  291.         set gWinVoiceSuspended to hWinVoiceMicState()
  292.         gWinVoiceXobj(mSetMicState, 0)
  293.         set gWINListenStatus to 0
  294.       end if
  295.     end if
  296.   end if
  297. end
  298.  
  299. on hWinVoiceResume
  300.   if gWinVoiceSuspended <> 1 then
  301.     return 
  302.   end if
  303.   if objectp(gWinVoiceXobj) then
  304.     if (gModeState = #TOPICS) or gVidIsPlaying then
  305.       return 
  306.     end if
  307.     if gSpeechWasChosenF = 0 then
  308.       return 
  309.     end if
  310.     if gWinVoiceEnabled = 1 then
  311.       if gWINListenStatus = 0 then
  312.         repeat while soundBusy(1)
  313.           nothing()
  314.         end repeat
  315.         repeat while soundBusy(2)
  316.           nothing()
  317.         end repeat
  318.         puppetSound(0)
  319.         updateStage()
  320.         gWinVoiceXobj(mSetMicState, 1)
  321.         put "after setmicstate, mic = " & gWinVoiceXobj(mGetMicState)
  322.         set gWINListenStatus to 1
  323.       end if
  324.     end if
  325.   end if
  326. end
  327.  
  328. on hWinVoiceMicState
  329.   if gVoiceDisabled = "1" then
  330.     return 0
  331.   end if
  332.   if objectp(gWinVoiceXobj) then
  333.     set micIsOn to gWinVoiceXobj(mGetMicState)
  334.     return micIsOn
  335.   else
  336.     return 0
  337.   end if
  338. end
  339.  
  340. on hWinVoiceIdle dontUpdateInterface
  341.   global gdescfield, gSpeechCapable, gComputerTypeK
  342.   if gComputerTypeK <> #WIN then
  343.     return 
  344.   end if
  345.   if gSpeechCapable = 0 then
  346.     return 
  347.   end if
  348.   if gVoiceDisabled = "1" then
  349.     set gWINListenStatus to 0
  350.     set gWinVoiceEnabled to 0
  351.     if dontUpdateInterface <> 1 then
  352.       hShowSpeechStatus(#null)
  353.     end if
  354.     return 
  355.   end if
  356.   if gWinVoiceStartedWaiting > 0 then
  357.     if (the ticks - gWinVoiceStartedWaiting) > 300 then
  358.       set gWinVoiceStartedWaiting to 0
  359.       hReportStatus("Speech Ready...")
  360.     end if
  361.   end if
  362.   if gWinVoiceEnabled <> 1 then
  363.     if dontUpdateInterface <> 1 then
  364.       hShowSpeechStatus(#INACTIVE)
  365.     end if
  366.     return 
  367.   end if
  368.   set micIsOn to gWinVoiceXobj(mGetMicState)
  369.   if gVoiceCmd = EMPTY then
  370.     if micIsOn = 1 then
  371.       if dontUpdateInterface <> 1 then
  372.         hShowSpeechStatus(#READY)
  373.       end if
  374.     else
  375.       if dontUpdateInterface <> 1 then
  376.         hShowSpeechStatus(#STANDBY)
  377.       end if
  378.     end if
  379.   else
  380.     if dontUpdateInterface <> 1 then
  381.       hReportStatus("Interpreting >" & gVoiceCmd & "<")
  382.     end if
  383.     set gVoiceConfidence to integer(gVoiceConfidence)
  384.     if gVoiceConfidence < 10 then
  385.       hFlushWINvoiGlobals()
  386.       hReportStatus(" Could not recognize command, please try again. Speak clearly and loudly.")
  387.     else
  388.       if gVoiceHandler <> EMPTY then
  389.         if dontUpdateInterface <> 1 then
  390.           hReportStatus("Executing >" & gVoiceCmd & "<")
  391.         end if
  392.         if word 1 of gVoiceHandler contains "Link" then
  393.           set Lcmd to gVoiceHandler
  394.           hFlushWINvoiGlobals()
  395.           do(Lcmd)
  396.         else
  397.           hCancel()
  398.           set Lcmd to gVoiceHandler
  399.           hFlushWINvoiGlobals()
  400.           do(Lcmd)
  401.         end if
  402.       end if
  403.       hFlushWINvoiGlobals()
  404.     end if
  405.   end if
  406. end
  407.  
  408. on hFlushWINvoiGlobals
  409.   set gVoiceCmd to EMPTY
  410.   set gVoiceHandler to EMPTY
  411.   set gVoiceConfidence to EMPTY
  412. end
  413.  
  414. on hClose
  415. end
  416.